package ru.st.selenium.pages;

import static org.openqa.selenium.support.ui.ExpectedConditions.presenceOfElementLocated;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;

public class AddMoviePage extends InternalPage {

	public AddMoviePage(PageManager pages) {
		super(pages);
	}

	@FindBy(css = ("img[alt=\"Save\"]"))
	private WebElement SaveIcon;

	@FindBy(name = "imdbsearch")
	private WebElement imdbsearchField;

	@FindBy(className = "input[type=\"submit\"]")
	private WebElement SearchButton;

	@FindBy(name = "imdbid")
	private WebElement imdNumberField;

	@FindBy(name = "name")
	private WebElement TitleField;

	@FindBy(name = "aka")
	private WebElement AkaField;

	@FindBy(name = "year")
	private WebElement YearField;

	@FindBy(name = "duration")
	private WebElement DurationField;

	@FindBy(name = "rating")
	private WebElement RatingField;

	@FindBy(name = "format")
	private WebElement FormatField;

	@FindBy(id = "own_yes")
	private WebElement own_yesRadioButton;

	@FindBy(id = "own_no")
	private WebElement own_noRadioButton;

	@FindBy(id = "seen_yes")
	private WebElement seen_yesRadioButton;

	@FindBy(id = "seen_no")
	private WebElement seen_noRadioButton;

	@FindBy(id = "loaned_yes")
	private WebElement loaned_yesRadioButton;

	@FindBy(id = "loaned_no")
	private WebElement loaned_noRadioButton;

	@FindBy(id = "cover")
	private WebElement CoverButton;

	@FindBy(name = "trailer")
	private WebElement TrailerField;

	@FindBy(name = "notes")
	private WebElement NotesField;

	@FindBy(name = "taglines")
	private WebElement TaglinesField;

	@FindBy(name = "plotoutline")
	private WebElement PlotoutlineField;

	@FindBy(name = "plots")
	private WebElement PlotsField;

	@FindBy(id = "text_languages_0")
	private WebElement Text_languages_0Field;

	@FindBy(name = "subtitles")
	private WebElement SubtitlesField;

	@FindBy(name = "audio")
	private WebElement AudioField;

	@FindBy(name = "video")
	private WebElement VideoField;

	@FindBy(name = "country")
	private WebElement CountryField;

	@FindBy(name = "genres")
	private WebElement GenresField;

	@FindBy(name = "director")
	private WebElement DirectorField;

	@FindBy(name = "writer")
	private WebElement WriterField;

	@FindBy(name = "producer")
	private WebElement ProducerField;

	@FindBy(name = "music")
	private WebElement MusicField;

	@FindBy(name = "cast")
	private WebElement CastField;

	@FindBy(id = "submit")
	private WebElement SaveButton;

	@FindBy(xpath = "//form[@id='updateform']/table/tbody/tr[2]/td[2]/label")
	private WebElement TitleErrorLabel;

	@FindBy(xpath = "//form[@id='updateform']/table/tbody/tr[4]/td[2]/label")
	private WebElement YearErrorLabel;

	@FindBy(xpath = "//form[@id='updateform']/table/tbody/tr[7]/td[2]/label")
	private WebElement FormatErrorLabel;

	@FindBy(xpath = "//form[@id='updateform']/table/tbody/tr[4]/td[2]/label")
	private WebElement YearNotNumberLabel;

	public AddMoviePage setIMDbnumberValue(String text) {
		imdNumberField.sendKeys(text);
		return this;
	}

	public AddMoviePage setTitleValue(String text) {
		TitleField.clear();
		TitleField.sendKeys(text);
		return this;
	}

	public AddMoviePage clearTitleValue() {
		TitleField.clear();
		return this;
	}

	public AddMoviePage setAkaValue(String text) {
		AkaField.clear();
		AkaField.sendKeys(text);
		return this;
	}

	public AddMoviePage setYearValue(String text) {
		YearField.clear();
		YearField.sendKeys(text);
		return this;
	}

	public AddMoviePage clearYearValue() {
		YearField.clear();
		return this;
	}

	public AddMoviePage setDurationValue(String text) {
		DurationField.clear();
		DurationField.sendKeys(text);
		return this;
	}

	public AddMoviePage setRatingValue(String text) {
		RatingField.sendKeys(text);
		return this;
	}

	public AddMoviePage setFormatValue(String text) {
		FormatField.clear();
		FormatField.sendKeys(text);
		return this;
	}

	public AddMoviePage clearFormatField() {
		FormatField.clear();
		return this;
	}

	public AddMoviePage selectOwn_yesRadioButton() {
		own_yesRadioButton.click();
		return this;
	}

	public AddMoviePage selectOwn_noRadioButton() {
		own_noRadioButton.click();
		return this;
	}

	public AddMoviePage selectSeen_yesRadioButton() {
		seen_yesRadioButton.click();
		return this;
	}

	public AddMoviePage selectSeen_noRadioButton() {
		seen_noRadioButton.click();
		return this;
	}

	public AddMoviePage selectLoaned_yesRadioButton() {
		loaned_yesRadioButton.click();
		return this;
	}

	public AddMoviePage selectLoaned_noRadioButton() {
		loaned_noRadioButton.click();
		return this;
	}

	public AddMoviePage selectCover(String text) {
		CoverButton.sendKeys(text);
		return this;
	}

	public AddMoviePage setTrailerValue(String text) {
		TrailerField.sendKeys(text);
		return this;
	}

	public AddMoviePage setNotesValue(String text) {
		NotesField.sendKeys(text);
		return this;
	}

	public AddMoviePage setTaglinesValue(String text) {
		TaglinesField.sendKeys(text);
		return this;
	}

	public AddMoviePage setPlotOutlineValue(String text) {
		PlotoutlineField.sendKeys(text);
		return this;
	}

	public AddMoviePage setPlotsValue(String text) {
		PlotsField.sendKeys(text);
		return this;
	}

	public AddMoviePage setText_languageValue(String text) {
		Text_languages_0Field.sendKeys(text);
		return this;
	}

	public AddMoviePage setSubtitlesValue(String text) {
		SubtitlesField.sendKeys(text);
		return this;
	}

	public AddMoviePage setAudioValue(String text) {
		AudioField.sendKeys(text);
		return this;
	}

	public AddMoviePage setVideoValue(String text) {
		VideoField.sendKeys(text);
		return this;
	}

	public AddMoviePage setCountryValue(String text) {
		CountryField.sendKeys(text);
		return this;
	}

	public AddMoviePage setGenresValue(String text) {
		GenresField.sendKeys(text);
		return this;
	}

	public AddMoviePage setDirectorValue(String text) {
		DirectorField.sendKeys(text);
		return this;
	}

	public AddMoviePage setWriterValue(String text) {
		WriterField.sendKeys(text);
		return this;
	}

	public AddMoviePage setProducerValue(String text) {
		ProducerField.sendKeys(text);
		return this;
	}

	public AddMoviePage setMusicValue(String text) {
		MusicField.sendKeys(text);
		return this;
	}

	public AddMoviePage setCastValue(String text) {
		CastField.sendKeys(text);
		return this;
	}

	public void clickSaveButton() {
		SaveButton.click();
	}

	public void clickSaveIcon() {
		SaveIcon.click();
	}

	public void isTitleErrorLabelPresent() {
		TitleErrorLabel.isDisplayed();
	}

	public void isYearErrorLabelPresent() {
		YearErrorLabel.isDisplayed();
	}

	public void isYearNotNumberErrorLabelPresent() {
		YearNotNumberLabel.isDisplayed();
	}

	public AddMoviePage ensurePageLoaded() {
		super.ensurePageLoaded();
		// wait.until(presenceOfElementLocated(By.cssSelector("img[alt=\"Save\"]")));
		wait.until(presenceOfElementLocated(By.id("imbdsearch")));
		return this;
	}
}
